home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / ODF / Form / Sources / Commands.cpp < prev    next >
Encoding:
Text File  |  1996-06-03  |  8.8 KB  |  286 lines  |  [TEXT/CWIE]

  1. //========================================================================================
  2. //
  3. //    File:                Commands.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Form.hpp"
  11.  
  12. #ifndef COMMANDS_H
  13. #include "Commands.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef CONTENT_H
  21. #include "Content.h"
  22. #endif
  23.  
  24. // ----- Framework Includes -----
  25.  
  26. #ifndef FWPRESEN_H
  27. #include "FWPresen.h"
  28. #endif
  29.  
  30. // ----- OpenDoc Includes -----
  31.  
  32. #ifndef SOM_Module_OpenDoc_Commands_defined
  33. #include <CmdDefs.xh>
  34. #endif
  35.  
  36. //========================================================================================
  37. // RunTime Info
  38. //========================================================================================
  39.  
  40. #ifdef FW_BUILD_MAC
  41. #pragma segment Form
  42. #endif
  43.  
  44. FW_DEFINE_AUTO(CFormEditCommand)
  45. FW_DEFINE_AUTO(CFormDropCommand)
  46. FW_DEFINE_AUTO(CFormDragCommand)
  47.  
  48. //========================================================================================
  49. // CFormEditCommand
  50. //========================================================================================
  51.  
  52. //----------------------------------------------------------------------------------------
  53. //    CFormEditCommand constructor
  54. //----------------------------------------------------------------------------------------
  55.  
  56. CFormEditCommand::CFormEditCommand(Environment* ev,
  57.                                      ODCommandID id,
  58.                                      CFormContent* itsContent,
  59.                                      FW_CFrame* frame) :
  60.     FW_CClipboardCommand(ev, id, frame, FW_kCanUndo),
  61.     fFormContent(itsContent)
  62. {
  63.     switch (id)
  64.     {
  65.         case kODCommandCut:
  66.             SetMenuStringsFromResource(ev, kFormUndoStrings, kUndoCutTextMsg, kRedoCutTextMsg);
  67.             break;
  68.         case kODCommandClear:
  69.             SetMenuStringsFromResource(ev, kFormUndoStrings, kUndoClearTextMsg, kRedoClearTextMsg);
  70.             break;
  71.         case kODCommandPaste:
  72.             SetMenuStringsFromResource(ev, kFormUndoStrings, kUndoPasteTextMsg, kRedoPasteTextMsg);
  73.             break;
  74.     }
  75.     FW_END_CONSTRUCTOR
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. //    CFormEditCommand destructor
  80. //----------------------------------------------------------------------------------------
  81.  
  82. CFormEditCommand::~CFormEditCommand()
  83. {
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. //    CFormEditCommand::SaveUndoState
  88. //----------------------------------------------------------------------------------------
  89.  
  90. void CFormEditCommand::SaveUndoState(Environment *ev)
  91. {
  92.      fSavedTextData = fFormContent->GetTextData();
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. //    CFormEditCommand::UndoIt
  97. //----------------------------------------------------------------------------------------
  98.  
  99. void CFormEditCommand::UndoIt(Environment* ev)
  100. {
  101.     FW_CClipboardCommand::UndoIt(ev);    // call inherited
  102.  
  103.     switch (GetCommandID(ev))
  104.     {
  105.         case kODCommandCut:
  106.         case kODCommandClear:
  107.             this->RestoreSelection(ev);
  108.             break;
  109.  
  110.         case kODCommandPaste:
  111.             this->SwapSelection(ev);
  112.             break;
  113.     }    
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    CFormEditCommand::RedoIt
  118. //----------------------------------------------------------------------------------------
  119.  
  120. void CFormEditCommand::RedoIt(Environment *ev)
  121. {
  122.     FW_CClipboardCommand::RedoIt(ev);    // call inherited
  123.  
  124.     switch (GetCommandID(ev))
  125.     {
  126.         case kODCommandCut:
  127.         case kODCommandClear:
  128.             this->RemoveSelection(ev);
  129.             break;
  130.  
  131.         case kODCommandPaste:
  132.             this->SwapSelection(ev);
  133.             break;
  134.     }    
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    CFormEditCommand::RemoveSelection
  139. //----------------------------------------------------------------------------------------
  140.  
  141. void CFormEditCommand::RemoveSelection(Environment* ev)
  142. {
  143.     fFormContent->ClearTextData(ev);
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. //    CFormEditCommand::RestoreSelection
  148. //----------------------------------------------------------------------------------------
  149.  
  150. void CFormEditCommand::RestoreSelection(Environment* ev)
  151. {
  152.     fFormContent->SetTextData(ev, fSavedTextData);
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    CFormEditCommand::SwapSelection
  157. //----------------------------------------------------------------------------------------
  158.  
  159. void CFormEditCommand::SwapSelection(Environment* ev)
  160. {
  161.     FW_CString255 textData = fFormContent->GetTextData();
  162.     fFormContent->SetTextData(ev, fSavedTextData);
  163.     fSavedTextData = textData;
  164. }
  165.  
  166. //========================================================================================
  167. // CFormDragCommand
  168. //========================================================================================
  169.  
  170. //----------------------------------------------------------------------------------------
  171. //    CFormDragCommand constructor
  172. //----------------------------------------------------------------------------------------
  173.  
  174. CFormDragCommand::CFormDragCommand(Environment* ev,
  175.                                      CFormContent* content,
  176.                                      FW_CFrame* frame) :
  177.     FW_CDragCommand(ev, frame, FW_kCanUndo),
  178.     fFormContent(content)
  179. {
  180.     SetMenuStringsFromResource(ev, kFormUndoStrings, kUndoDragTextMsg, kRedoDragTextMsg);
  181.     FW_END_CONSTRUCTOR
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. //    CFormDragCommand destructor
  186. //----------------------------------------------------------------------------------------
  187.  
  188. CFormDragCommand::~CFormDragCommand()
  189. {
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    CFormDragCommand::SaveUndoState
  194. //----------------------------------------------------------------------------------------
  195.  
  196. void CFormDragCommand::SaveUndoState(Environment *ev)
  197. {
  198.      fSavedTextData = fFormContent->GetTextData();
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    CFormDragCommand::UndoIt
  203. //----------------------------------------------------------------------------------------
  204.  
  205. void CFormDragCommand::UndoIt(Environment* ev)
  206. {
  207.     fFormContent->SetTextData(ev, fSavedTextData);
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    CFormDragCommand::RedoIt
  212. //----------------------------------------------------------------------------------------
  213.  
  214. void CFormDragCommand::RedoIt(Environment* ev)
  215. {
  216.     fFormContent->ClearTextData(ev);
  217. }
  218.  
  219. //========================================================================================
  220. // CFormDropCommand
  221. //========================================================================================
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    CFormDropCommand constructor
  225. //----------------------------------------------------------------------------------------
  226.  
  227. CFormDropCommand::CFormDropCommand(Environment *ev,
  228.                                      CFormContent* content,
  229.                                      FW_CFrame* frame,
  230.                                      ODDragItemIterator* dropInfo, 
  231.                                      ODFacet* odFacet,
  232.                                      const FW_CPoint& dropPoint) : 
  233.     FW_CDropCommand(ev, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
  234.     fFormContent(content)
  235. {
  236.     SetMenuStringsFromResource(ev, kFormUndoStrings, kUndoDropTextMsg, kRedoDropTextMsg);
  237.     FW_END_CONSTRUCTOR
  238. }
  239.  
  240. //----------------------------------------------------------------------------------------
  241. //    CFormDropCommand destructor
  242. //----------------------------------------------------------------------------------------
  243.  
  244. CFormDropCommand::~CFormDropCommand()
  245. {
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    CFormDropCommand::SaveUndoState
  250. //----------------------------------------------------------------------------------------
  251.  
  252. void CFormDropCommand::SaveUndoState(Environment *ev)
  253. {
  254.      fSavedTextData = fFormContent->GetTextData();
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //    CFormDropCommand::UndoIt
  259. //----------------------------------------------------------------------------------------
  260.  
  261. void CFormDropCommand::UndoIt(Environment* ev)
  262. {
  263.     this->SwapSelection(ev);
  264. }
  265.  
  266. //----------------------------------------------------------------------------------------
  267. //    CFormDropCommand::RedoIt
  268. //----------------------------------------------------------------------------------------
  269.  
  270. void CFormDropCommand::RedoIt(Environment* ev)
  271. {
  272.     this->SwapSelection(ev);
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    CFormDropCommand::SwapSelection
  277. //----------------------------------------------------------------------------------------
  278.  
  279. void CFormDropCommand::SwapSelection(Environment* ev)
  280. {
  281.     FW_CString255 textData = fFormContent->GetTextData();
  282.     fFormContent->SetTextData(ev, fSavedTextData);
  283.     fSavedTextData = textData;
  284. }
  285.  
  286.